package com.syg.servlet01;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;

/**
 * 设置浏览器头信息
 * 设置Location响应头，实现请求重定向
 */
public class _02_Browser extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取输出流
        OutputStream out = resp.getOutputStream();
        out.write("设置Location响应头，实现请求重定向".getBytes());

        /**
         *设置响应头，服务器通过 Location这个头，来告诉浏览器跳到哪里，这就是所谓的请求重定向
         */
        resp.setHeader("Location", "/JavaServlet/index.jsp");

    }
}
